package models;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import objects.FeaturesDatabase;
import objects.Lexicon;

/* Reads from and Writes to XML files */
public class LexiconFeaturesModel {
	
	/* static lexiconFeatures variable to remove need for creating LexiconFeatureModel objects */
	private static ArrayList<Lexicon> lexiconFeatures;
	
	public LexiconFeaturesModel() {}
	
	public static void read() throws ParserConfigurationException, SAXException, IOException {
		LexiconFeatureXMLReader reader = new LexiconFeatureXMLReader();
		reader.read("src/xml/features/lexiconfeatures.xml");
		lexiconFeatures = reader.getDatabase();
	}
	
	public static void write() throws FileNotFoundException, IOException {
		FeaturesDatabase db = new FeaturesDatabase();
		db.setLexicons(lexiconFeatures);
		
		LexiconFeatureXMLWriter writer = new LexiconFeatureXMLWriter();
		writer.setDatabase(db);
		writer.write("src/xml/features/lexiconfeatures.xml");
	}
	
	/** Get/Set data **/
	
	public static void setLexiconFeatures(ArrayList<Lexicon> newLexiconFeatures) {
		lexiconFeatures = newLexiconFeatures;
	}
	
	public static ArrayList<Lexicon> getLexiconFeatures() {
		return lexiconFeatures;
	}
}
